package com.qianchang.microfinance.view.hsbindbank;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.webkit.JavascriptInterface;

import com.qianchang.microfinance.view.credit.data.ScanFaceActivity;
import com.just.agentweb.AgentWeb;

/**
 * Created by cenxiaozhong on 2017/5/14.
 *  source CODE  https://github.com/Justson/AgentWeb
 */

public class AndroidInterface {

    private Handler deliver = new Handler(Looper.getMainLooper());
    private AgentWeb agent;
    private Context context;
    private HSAuthorizedActivity hsAuthorizedActivity;


    public AndroidInterface(AgentWeb agent, Context context) {
        this.agent = agent;
        this.context = context;
        this.hsAuthorizedActivity = (HSAuthorizedActivity) context;
    }



    @JavascriptInterface
    public void mSkipBack(final String action, final String result) {


        deliver.post(new Runnable() {
            @Override
            public void run() {
                Log.i("Info", "main Thread:" + Thread.currentThread());
                if(action.equals("openAccount") && result.equals("success")){            //授权成功返回页面按钮
                    if(hsAuthorizedActivity.isConfirmlGoing()){
                        hsAuthorizedActivity.finish();
                    }else{
                        Intent intent = new Intent();
                        intent.setClass(hsAuthorizedActivity,ScanFaceActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putBoolean("isConfirml",false);
                        intent.putExtras(bundle);
                        hsAuthorizedActivity.startActivity(intent);
                        hsAuthorizedActivity.finish();
//                        startActivity(ScanFaceActivity.class, bundle);                  //第一次银行卡授权绑定成功走人脸识别
                    }
                }else {
                    hsAuthorizedActivity.finish();
                }
            }
        });
        Log.i("Info", "Thread:" + Thread.currentThread());
    }

}
